﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>设置查询条件</title>
    <link href="../../../DataUser/Style/ccbpm.css" rel="Stylesheet" />
    <script src="../../Scripts/easyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">

        var frmID = GetQueryString("FrmID");

        //页面启动函数.
        $(function () {

            $("#Msg").html("<img src=../../../Img/loading.gif />&nbsp;正在加载,请稍后......");

            InitPage();

            $("#Msg").html("");

        });

        function InitPage() {

            var checkBoxIDs = GetSelectedCheckIDs();

            var mapAttrs = new Entities("BP.Sys.MapAttrs");
            mapAttrs.Retrieve("FK_MapData", frmID);

            var mapData = new Entity("BP.Sys.MapData", frmID);

            // var md = jsData["Main"][0]; //主表数据.
            // var Sys_MapAttr = jsData["Sys_MapAttr"]; //所有的列.
            // var Sys_MapAttrOfDate = jsData["Sys_MapAttrOfDate"]; //日期列表.

            //关键字查询.
            document.getElementById("CB_Key").checked = true; //  (mapData.AtPara.indexOf("@RptIsSearchKey=1@") != -1);

            var js = mapData.AtPara.split("@");
            var RptSearchKeys = null;
            var RptDTSearchWay = null;
            var RptDTSearchKey = null;
            for (var i = 0; i < js.length; i++) {
                if (js[i].indexOf("RptSearchKeys") != -1)
                    RptSearchKeys = js[i].replace("RptSearchKeys=", "")
                if (js[i].indexOf("DTSearchWay") != -1)
                    RptDTSearchWay = js[i].replace("DTSearchWay=", "")
                if (js[i].indexOf("DTSearchKey") != -1)
                    RptDTSearchKey = js[i].replace("DTSearchKey=", "")
            }

            //绑定外键字段.
            var dateMapAttrs = [];
            for (var i = 0, length = mapAttrs.length; i < length; i++) {

                var attr = mapAttrs[i];
                if (attr.MyDataType == 6 || attr.MyDataType == 7) {
                    dateMapAttrs.push(attr);
                    continue;
                }

                if (attr.UIBindKey == ""   ) {
                    continue;
                }
                if ( attr.UIVisible == 0) {
                    continue;
                }  

                flag = false;
                if (RptSearchKeys) {
                    flag = (RptSearchKeys.indexOf("*" + attr.KeyOfEn + "*") != -1);
                }

                $("#FKeys").append("<input type='checkbox' " + (flag ? "checked = 'checked'" : "") + " id='" + attr.KeyOfEn + "' /><label for='" + attr.KeyOfEn + "' >" + attr.Name + "(" + attr.KeyOfEn + ")</label></br>");
            }

            $("#DDL_DTSearchWay").val(RptDTSearchWay);

            //绑定日期下拉框.
            if (dateMapAttrs != null) {
                GenerBindDDL("DDL_DTSearchKey", dateMapAttrs, "KeyOfEn", "Name", RptDTSearchKey);
            }

        }

        function Save() {

            var mapData = new Entity("BP.Sys.MapData", frmID);

            var checked = document.getElementById("CB_Key").checked ? 1 : 0;
            mapData.SetPara("IsSearchKey", checked);

            mapData.SetPara("DTSearchWay", document.getElementById("DDL_DTSearchWay").value);
            mapData.SetPara("DTSearchKey", document.getElementById("DDL_DTSearchKey").value);
            mapData.SetPara("DTSearchLabel", $("#DDL_DTSearchKey").find("option:selected").text());

            var fields = "";
            var oChecks = document.getElementById("FKeys").getElementsByTagName("input");
            for (var i = 0, len = oChecks.length; i < len; i++) {
                var item = oChecks[i];
                if (item.checked) {
                    fields += "*" + item.id;
                }
            }

            mapData.SetPara("RptSearchKeys", fields + "*");
            mapData.Update();

            window.location.href = window.location.href;

        }

        //获得所有的checkbox 的id组成一个string用逗号分开, 以方便后台接受的值保存.
        function GetSelectedCheckIDs() {

            var checkBoxIDs = "";
            var arrObj = document.getElementsByTagName("input");

            for (var i = 0, len = arrObj.length; i < len; i++) {

                if (arrObj[i].type == 'checkbox') {
                    if (arrObj[i].checked)
                        checkBoxIDs += arrObj[i].id + ',';
                }
            }
            return checkBoxIDs;
        }

    </script>
    <base target="_self" />
</head>
<body>
    <form id="cc">
    <table style="width: 96%;">
        <caption>
            设置查询条件</caption>
        <tr>
            <th>
                关键字查询
            </th>
        </tr>
        <tr>
            <td>
                关键字查询是接受用户输入一个关键字，在整个报表的显示列中使用like查询(外键、枚举、数值类型的除外)<br>
                <input id="CB_Key" type="checkbox" name="CB_Key" /><label for="CB_Key">是否增加关键字查询</label>
                <br />
                关键字搜索提示
                <input id="TB_Alert" name="TB_Alert" type="text" value="" />,默认为:请输入关键字...
            </td>
        </tr>
        <tr>
            <th>
                外键与枚举类型,的查询
            </th>
        </tr>
        <tr>
            <td>
                <div id="FKeys">
                </div>
            </td>
        </tr>
        <tr>
            <th>
                时间段的查询
            </th>
        </tr>
        <tr>
            <td>
                对数据按照时间段进行查询，比如：按流程的发起时间，在指定时间段内进行查询。<br>
                选择方式：<select name="DDL_DTSearchWay" id="DDL_DTSearchWay">
                    <option selected="selected" value="0">不启用</option>
                    <option value="1">按日期</option>
                    <option value="2">按日期时间</option>
                </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;字段：<select name="DDL_DTSearchKey" id="DDL_DTSearchKey">
            </td>
        </tr>
    </table>
    <input type="button" value="保存" onclick="Save();" />
    </form>
</body>
</html>
